package com.twu.biblioteca.domain;

/**
 * Created by mnewman on 30/07/2014.
 */
public class Movie implements LibraryItem {

    public final String title;
    public final String director;
    public final int year;
    public final Integer rating;

    public Movie(String title, int year, String director, Integer rating) {
        this.title = title;
        this.director = director;
        this.year = year;
        this.rating = rating;
    }

    @Override
    public String getID() {
        return title;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Movie movie = (Movie) o;

        if (year != movie.year) return false;
        if (!director.equals(movie.director)) return false;
        if (rating != null ? !rating.equals(movie.rating) : movie.rating != null) return false;
        if (!title.equals(movie.title)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = title.hashCode();
        result = 31 * result + director.hashCode();
        result = 31 * result + year;
        result = 31 * result + (rating != null ? rating.hashCode() : 0);
        return result;
    }
}
